home *** CD-ROM | disk | FTP | other *** search
/ Aminet 13 / Aminet 13 - August 1996.iso / Aminet / dev / e / energy.lha / Energy / Easy / Kriptonyte.e < prev    next >
Text File  |  1996-05-18  |  2KB  |  68 lines

  1. /* Kriptonyte v 2.3 by Marco Talamelli ( 28-11-1995 )     */
  2. /* cripta un file ascii con una password        */
  3.  
  4. OPT OSVERSION=37
  5.  
  6. ENUM ERR_SHORT, ERR_MEM, ERR_IO, ERR_FILE, ERR_ARGS, ERR_NONE
  7.  
  8. ENUM ARG_FROM, ARG_TO,PASS,OPT_ASCII
  9.  
  10. RAISE ERR_ARGS IF ReadArgs()=NIL,
  11.       ERR_MEM  IF New()=NIL,
  12.       ERR_FILE IF Open()=NIL
  13.  
  14. PROC main() HANDLE
  15.   DEF password:PTR TO CHAR,dentro:PTR TO CHAR, fuori:PTR TO CHAR,count,
  16.       sorgente=NIL, destinazione=NIL, lunghezza, max, bin=NIL, bout=NIL,
  17.       errori:PTR TO LONG, argomenti=NIL, args:PTR TO LONG, numero=0,template
  18.   args:=[0, 0 ,0, 0]
  19.   template:='FROM/A,TO/A,PASSWORD/A,ASCII/S'
  20.   argomenti:=ReadArgs(template, args, NIL)
  21.   sorgente:=Open(args[ARG_FROM], OLDFILE)
  22.   IF (lunghezza:=FileLength(args[ARG_FROM]))=0 THEN Raise(ERR_SHORT)
  23.   IF args[ARG_TO]
  24.     destinazione:=Open(args[ARG_TO], NEWFILE)
  25.   ELSE
  26.     WriteF('')
  27.     destinazione:=stdout
  28.   ENDIF
  29.     WriteF('Kriptonyte v2.3 by Marco Talamelli (28-11-1995)\n')
  30.     WriteF(IF args[OPT_ASCII] THEN 'DECRIPTO...\n' ELSE 'CRIPTO..\n')
  31.   bin:=New(lunghezza)
  32.   bout:=New(lunghezza)
  33.   IF (Read(sorgente, bin, lunghezza)<>lunghezza) THEN Raise(ERR_IO)
  34.   dentro:=bin
  35.   fuori:=bout
  36.   password:=args[PASS]
  37.   count:= StrLen(password)
  38.   max:=bin+lunghezza
  39.   WHILE dentro<max
  40.  
  41. IF args[OPT_ASCII]
  42.         fuori[]++:= IF (dentro[]-password[numero]+count)<0 THEN (dentro[]+count+127-password[numero]) ELSE dentro[]-password[numero]+count
  43.  IF count=numero THEN numero:=0 ELSE numero++
  44. ELSE
  45.  
  46.         fuori[]++:= IF (dentro[]+password[numero]-count)>127 THEN (dentro[]+password[numero]-count-127) ELSE dentro[]+password[numero]-count
  47.  IF count=numero THEN numero:=0 ELSE numero++
  48. ENDIF
  49.     dentro++
  50.  
  51.   ENDWHILE
  52.   Write(destinazione, bout, fuori-bout)
  53.   Raise(ERR_NONE)
  54. EXCEPT
  55.   errori:=['Il File è vuoto\n', 'Non posso allocare memoria\n',
  56.            'File leggendo errore\n'] 
  57.   IF destinazione THEN Close(destinazione)
  58.   IF sorgente THEN Close(sorgente)
  59.   IF argomenti THEN FreeArgs(argomenti)
  60.   IF exception=ERR_FILE
  61.     WriteF('File "\s" non trovato!\n', args[ARG_FROM])
  62.   ELSEIF exception=ERR_ARGS
  63.     WriteF('Usage: Kriptonyte "\s"\n', template)
  64.   ELSEIF exception<>ERR_NONE
  65.     WriteF(errori[exception])
  66.   ENDIF
  67. ENDPROC
  68.